/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bash.carrep.ui.util;

import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;

/**
 *
 * @author p.bashizi
 */
 
    public class IntegerValidator implements Validator {
        
        private String message;
        
        public IntegerValidator(String message) {
            this.message = message;
        }
        
    @Override
        public boolean isValid(Object value) {
            if (value == null || !(value instanceof String)) {
                return false;
            }
            try {
                Integer.parseInt((String) value);
            } catch (Exception e) {
                return false;
            }
            return true;
        }
        
    @Override
        public void validate(Object value) throws InvalidValueException {
            if (!isValid(value)) {
                throw new InvalidValueException(message);
            }
        }
    }
